{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import sys, string, os, shutil  \n",
    "#输入目录名和前缀名，重命名后的名称结构类似prefix_0001  \n",
    "def RenameFiles(srcdir, prefix):  \n",
    "    srcfiles = os.listdir(srcdir)  \n",
    "    index = 1  \n",
    "    for srcfile in srcfiles:  \n",
    "        srcfilename = os.path.splitext(srcfile)[0][1:]  \n",
    "        sufix = os.path.splitext(srcfile)[1]  \n",
    "        #根据目录下具体的文件数修改%号后的值，\"%04d\"最多支持9999  \n",
    "        destfile = srcdir + \"//\" + prefix + \"%d\"%(index) + sufix  \n",
    "        srcfile = os.path.join(srcdir, srcfile)  \n",
    "        os.rename(srcfile, destfile)  \n",
    "        index += 1  \n",
    "srcdir = \"test/驯鹿\"  \n",
    "prefix = \"reindeer.\"  \n",
    "RenameFiles(srcdir, prefix)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
